<script setup lang="ts">
import { ref } from "vue";

// 传值
const props = defineProps({
  userList: {
    type: Array<any>,
    default: () => []
  }
});

const ruleFormRef = ref();
const form = ref({
  targetUserId: null,
  originUserId: null,
  score: null
});

const formRules = {
  targetUserId: [{ required: true, message: "请选择", trigger: "change" }],
  originUserId: [{ required: true, message: "请选择", trigger: "change" }],
  score: [{ required: true, message: "请输入", trigger: "change" }]
};

function getRef() {
  return ruleFormRef.value;
}
function getFormVal() {
  return form.value;
}

defineExpose({ getRef, getFormVal });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="form"
    :rules="formRules"
    label-width="120px"
    class="mr-12"
  >
    <el-form-item label="给予对象" prop="targetUserId">
      <el-select v-model="form.targetUserId" clearable placeholder="请选择">
        <el-option
          v-for="item in userList"
          :key="item.id"
          :label="item.name"
          :value="item.id"
        />
      </el-select>
    </el-form-item>
    <el-form-item label="被给予对象" prop="originUserId">
      <el-select v-model="form.originUserId" clearable placeholder="请选择">
        <el-option
          v-for="item in userList"
          :key="item.id"
          :label="item.name"
          :value="item.id"
        />
      </el-select>
    </el-form-item>
    <el-form-item label="积分数量" prop="score">
      <el-input-number
        v-model="form.score"
        :min="0"
        placeholder="请输入"
        class="!w-[200px]"
      />
    </el-form-item>
  </el-form>
</template>
